/**
 * Copyright (C) 2010-2011 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.seequencer.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ToggleButton;
import com.google.gwt.user.client.ui.VerticalPanel;

public class InstrumentLaneView extends Composite implements
		InstrumentLane.View {
	
	
	private VerticalPanel verticalPanel;
	private InstrumentLane instrumentLane;

	public InstrumentLaneView() {
		verticalPanel = new VerticalPanel();
		
		initWidget(verticalPanel);
		
		doLayout();
	}
	
	
	private void doLayout() {
		
		int height = 5;
	    int length = 50;
		
		FlexTable flexTable = new FlexTable();
		
	    FlexCellFormatter cellFormatter = flexTable.getFlexCellFormatter();
	    flexTable.addStyleName("cw-FlexTable");
	    flexTable.setWidth("32em");
	    flexTable.setCellSpacing(5);
	    flexTable.setCellPadding(3);
	    


		for (int row = 0; row < height; row++) {
			for (int col = 0; col < length; col++) {

				
				final int colo = col;
				final int rowo = row;

				ToggleButton button = new ToggleButton("#" + colo);
				button.addClickHandler(new ClickHandler() {

					@Override
					public void onClick(ClickEvent event) {			
						
						//+21 becuase of midi convention...
						instrumentLane.addNoteToPosition(colo, rowo+21);

					}
				});

				flexTable.setWidget(row, col, button);

			}
		}
		
		verticalPanel.add(new Label("Instrument Lane for TR909js"));
		verticalPanel.add(flexTable);
		
	}


	@Override
	public void setInstrumentLane(InstrumentLane instrumentLane) {
		this.instrumentLane = instrumentLane;
		
	}



}
